import requests
from api.login_api import LoginApi
from common.DBUtil import DBUtil
from config import BASE_URL

login_data = {"mobile": "13800000002", "password": "123456"}
resp_login = LoginApi.login(login_data)
token = "Bearer " + resp_login.json().get("data")
print(token)

sql = "delete from bs_user where mobile = '18210222335'"
DBUtil.uid_conn(sql)
add_emp_url = f"{BASE_URL}/api/sys/user"
headers = {"Content-Type": "application/json", "Authorization": token}
add_body = {"username": "YG001", "mobile": "18210222335", "workNumber": "123"}
resp_add_emp = requests.post(url=add_emp_url, headers=headers, json=add_body)
print(resp_add_emp.json())
id = resp_add_emp.json().get("data").get("id")

url_query = f"{BASE_URL}/api/sys/user/{id}"
resp_query = requests.get(url_query, headers=headers)
print("查询员工", resp_query.json())

url_modify = f"{BASE_URL}/api/sys/user/{id}"
body_modify = {"username": "tom-new", "password": "123456", "departmentId":"1066240656856453120"}
resp_modify = requests.put(url_modify, headers=headers, json=body_modify)
print("修改员工：", resp_modify.json())

# 删除员工
url_delete = f"{BASE_URL}/api/sys/user/{id}"
resp_delete = requests.delete(url_delete,headers=headers)
print("删除员工：",resp_delete.json())